#include "StdAfx.h"
#include "chat_log_manager_impl.h"
#include "dll_object.h"
#include <Util/WinAPITools.h>
namespace aot{ namespace tt{

chat_log_manager_impl::chat_log_manager_impl(void)
:dlg_chat_log_ptr_(new dlg_chat_log)
{
	this->html_view_ = NULL;
}

chat_log_manager_impl::~chat_log_manager_impl(void)
{
	//delete this;
	//dll_object::impl_ = NULL;
}

bool 
chat_log_manager_impl::create( HWND hparent, RECT r )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	BOOL res = this->dlg_chat_log_ptr_->Create(dlg_chat_log::IDD, CWnd::FromHandle(hparent));
	if ( !res )
	{
		return false;
	}

	this->dlg_chat_log_ptr_->MoveWindow(&r);
	this->dlg_chat_log_ptr_->ShowWindow(SW_SHOW);

	this->html_view_ = this->dlg_chat_log_ptr_->get_html_view();
	return true;
}

void 
chat_log_manager_impl::set_cur_page( int num )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if ( this->html_view_ )
	{
		this->html_view_->set_current_page( num );
	}
}

int 
chat_log_manager_impl::get_cur_page()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return this->html_view_->get_current_page();
}

void 
chat_log_manager_impl::set_chat_type( int type )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if ( this->html_view_ )
	{
		this->html_view_->set_chat_type( type );
	}
}

int 
chat_log_manager_impl::get_chat_type()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if ( this->html_view_ )
	{
		return this->html_view_->get_chat_type();
	}
	return -1;
}

void 
chat_log_manager_impl::show_chat_log()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if ( !this->html_view_ )
	{
		return;
	}
	this->html_view_->show_chat_log(this->session_id_);
}

void 
chat_log_manager_impl::del_sel_chat_log()
{

	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	this->dlg_chat_log_ptr_->del_sel_chat_log();
}

void 
chat_log_manager_impl::set_chat_log( const char* session_id )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if ( this->html_view_ )
	{
		this->session_id_ = session_id;
		this->html_view_->set_session_id( session_id );
		this->html_view_->set_show_chat_log_type(e_show_nomarl_chat_log);
	}
}

void 
chat_log_manager_impl::show_page_chat_log( int page /*= 1*/ )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if ( this->html_view_ )
	{
		this->html_view_->show_page_chat_log( page );
	}
}

int
chat_log_manager_impl::get_page_count()
{

	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return this->html_view_->get_page_count();
}

const char* 
chat_log_manager_impl::get_sel_chat_user_id()
{

	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return this->html_view_->get_sel_user_id();
}

const char* 
chat_log_manager_impl::get_sel_chat_nick_name()
{

	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return this->html_view_->get_sel_nick_name();
}

void 
chat_log_manager_impl::destroy()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	dlg_chat_log_ptr_->DestroyWindow();
	delete this;
}

HWND 
chat_log_manager_impl::get_wnd()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return dlg_chat_log_ptr_->m_hWnd;
}

void chat_log_manager_impl::show_sel_date_chat_log( const char* date_time )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	this->html_view_->show_sel_date_chat_log( date_time );
}

void 
chat_log_manager_impl::show_search_chat_log( const char* search_text )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	this->html_view_->show_search_chat_log(search_text);
}


void 
chat_log_manager_impl::move_window(LPCRECT ptr_rect, BOOL repaint/* = TRUE */)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	dlg_chat_log_ptr_->MoveWindow(ptr_rect, repaint);
}
/// 
BOOL 
chat_log_manager_impl::show_window(int cmd_show)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return dlg_chat_log_ptr_->ShowWindow(cmd_show);
}

}

}